<template>
	<view class="">
		<!-- 自提点list -->
		<view class="ziTi_list" v-if="ziTiList.length>0">
			<view class="ziTi_list_item" v-for="(item,index) in ziTiList" :key="index">
				<u-icon name="home-fill" size="40" color="#29E06E"></u-icon>
				<view class="ziTi_list_item_info" style="width: 40%;">
					<text>自提点：{{item.address}}</text>
					<text>手机号：{{item.phone}}</text>
				</view>
				<view class="" style="width: 30%;text-align: right;">
					<text style="color: #29E06E;font-size: 24rpx;margin-right: 20rpx;"
						@click="edit_adress(item)">编辑</text>
					<text style="color: #d43030;font-size: 24rpx;" @click="del_adress(item)">删除</text>
				</view>
			</view>
		</view>
		<view class="" v-else>
			<u-empty mode="data" text="暂未添加自提点">
			</u-empty>
		</view>

		<view class="footerBtn">
			<u-button color="#29E06E" size="large " text="大小尺寸" @click="add_ziTi">添加自提点</u-button>
		</view>
		<u-popup :show="show" @close="close" mode='center'>
			<view class="pop_area">
				<view class="pop_area_item">
					<text>详细地址</text>
					<u--input v-model="form.address" border="none" placeholder='请输入详细地址'></u--input>
				</view>
				<view class="pop_area_item">
					<text>联系电话</text>
					<u--input v-model="form.phone" border="none" placeholder='请输入联系电话'></u--input>
				</view>
				<view class="zz">
					<u-button size='small' type="info " @click="close()">取消</u-button>
					<u-button size='small' color="#29E06E" @click="submit_ziTi">确定</u-button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				ziTiList: [],
				show: false,
				form: {
					address: '',
					phone: '',
				},
				editid: '',
				flag: 'add'
			};
		},
		onLoad() {
			let z = uni.getStorageSync('userInfo').shanghuid;
			console.log('z', z)
			this.get_ziTiList()
		},
		onShow() {

		},
		methods: {
			close() {
				this.show = false;
			},
			get_ziTiList() {
				this.$req.post('/shanghu/tihuo', {
					shanghuid: uni.getStorageSync('userInfo').shanghuid
				}).then(res => {
					this.ziTiList = res.data.data
				})
			},
			add_ziTi() {
				this.show = true;
				this.flag = 'add';
			},
			submit_ziTi() {
				let url = '';

				if (this.flag == 'add') {
					this.$req.post('/shanghu/tihuoadd', {
						phone: this.form.phone,
						address: this.form.address,
						shanghuid:uni.getStorageSync('userInfo').shanghuid
					}).then(res => {
						uni.showToast({
							title: '已添加',
							icon: 'none'
						})
						this.get_ziTiList()
						this.show = false;
					})
				} else if (this.flag == 'edit') {
					this.$req.post('/shanghu/tihuoupdate', {
						phone: this.form.phone,
						address: this.form.address,
						id: this.editid
					}).then(res => {
						uni.showToast({
							title: '修改成功',
							icon: 'none'
						})
						this.get_ziTiList();
						this.show = false;
					})
				}

			},
			close() {
				this.show = false;
			},
			edit_adress(val) {
				this.show = true;
				this.flag = 'edit';
				this.form.phone = val.phone;
				this.form.address = val.address;
				this.editid = val.id;
			},
			del_adress(val) {
				this.$req.post('/shanghu/tihuodel', {
					id: val.id
				}).then(res => {
					uni.showToast({
						title: '删除成功',
						icon: 'none'
					})
					this.get_ziTiList()
				})
			}
		}

	}
</script>

<style>
	page {
		background-color: #F6F6F6;
	}

	.ziTi_list {
		padding: 20rpx;
	}

	.ziTi_list_item {
		display: flex;
		align-items: center;
		background-color: #fff;
		padding: 50rpx 20rpx;
		border-radius: 20rpx;
		filter: drop-shadow(2px 2px 3px #e5e5e5);
		margin-bottom: 20rpx;
		justify-content: space-between;

	}

	.ziTi_list_item_info {
		display: flex;
		flex-direction: column;
		margin-left: 20rpx;
		font-size: 24rpx;
	}

	.footerBtn {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
	}

	.pop_area {
		width: 700rpx;
		padding: 20rpx;
	}

	.pop_area_item {
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 26rpx;
		margin: 20rpx;
		
	}
	.pop_area_item text {
		margin-right: 20rpx;
		width: 30%;
	}
	.zz {
		display: flex;
		justify-content: space-around;
		margin-top: 150rpx;
	}
	.zz button {
		width: 30%;
	}
</style>